package com.loan.controller.app.bank;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.excel.ExcelResult;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.system.domain.ApplyEntity;
import com.loan.system.domain.BankEntity;
import com.loan.system.domain.vo.AddressImportVo;
import com.loan.system.domain.vo.BankImportVo;
import com.loan.system.listener.AddressImportListener;
import com.loan.system.listener.BankImportListener;
import com.loan.system.service.BankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author shiguang on 2022/9/14 14:49
 */
@Validated
@Api(value = "银行管理", tags = {"银行管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/bank")
public class BankController extends BaseController {

    private final BankService bankService;

    /**
     * 获取银行列表
     */
    @ApiOperation("获取银行列表")
    //@SaCheckPermissio("app:bank:list")
    @GetMapping("/page")
    public TableDataInfo<BankEntity> list(BankEntity entity, PageQuery pageQuery) {
        return bankService.selectPageBankList(entity, pageQuery);
    }

    @ApiOperation("导入银行列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "导入文件", dataType = "java.io.File", required = true),
    })
    @Log(title = "银行管理", businessType = BusinessType.IMPORT)
    //@SaCheckPermissio("app:bank:import")
    @PostMapping("/importData")
    public Result<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
        ExcelResult<BankImportVo> result = ExcelUtil.importExcel(file.getInputStream(), BankImportVo.class, new BankImportListener(updateSupport));
        return Result.ok(result.getAnalysis());
    }

    @ApiOperation("获取银行列表")
    @GetMapping("/list")
    public Result<List<BankEntity>> list() {
        return Result.ok(bankService.list());
    }

}
